package great.project.test.servce;

import great.project.common.http.Result;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * <div  style="border:2px solid none;margin:20px;padding:15px;font-size:24px;text-align:center;color:aqua;">
 *
 *  认证服务
 *
 *  </div>
 *
 * @author zhangshun
 * @date 2021/1/29 14:18
 */
@Service
public class AuthService {
    /**
     *  登录
     * @param username 用户名
     * @param password 密码
     * @return 结果
     */
    public Result<String> login(String username , String password){

        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        if (servletRequestAttributes != null) {
            HttpServletResponse response = servletRequestAttributes.getResponse();
            Cookie cookie = new Cookie("zhangsan","12" );
            if (response != null) {
                response.addCookie(cookie);
            }
        }

        return Result.success(username , password);
    }
}
